<?php

/**
 * 面包屑导航
 * @param type $paretnids
 * @param type $curName
 * @return type
 */
function crumbs($paretnids, $curName) {
    $parArr = explode(',', $paretnids);
    $menuModel = new \app\admin\model\AdminMenu();
    $menu = $menuModel->getAllMenu();

    $str = '<li><a href="/admin.php"><i class="fa fa-dashboard"></i>首页</a></li>';
    $i = 1;
    while (isset($parArr[$i])) {
        $pid = $parArr[$i];
        $str .= "<li><a href='" . url("{$menu[$pid]['c']}/{$menu[$pid]['a']}") . "'>{$menu[$pid]['name']}</a></li>";
        $menu = isset($menu[$pid]['child']) ? $menu[$pid]['child'] : [];
        $i++;
    }
    $str .= "<li class='active'>{$curName}</li>";
    return $str;
}

/**
 * 查询系统配置
 * @return type
 */
function getAdminConfigure() {
    return (new app\admin\model\AdminConfig())->getConf();
}

/**
 * 组装分类
 * @param type $type
 * @param type $data
 * @return type
 */
function typeStr($type, $data = []) {
    if (is_numeric($type)) {
        return isset($data[$type]) ? $data[$type] : '';
    } else {
        $typeArr = explode('-', trim($type, '-'));
        $str = [];
        foreach ($typeArr as $v) {
            if (isset($data[$v])) {
                $str[] = $data[$v];
            }
        }
        return implode(',', $str);
    }
}
